﻿using AutoMapper;
using B.S.BaseData.Domain;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infratructure.Interfares;
using B.S.BaseData.Read.Api.Application.Command.UserRoleCommand;
using B.S.BaseData.Read.Api.Dtos;
using MediatR;

namespace B.S.BaseData.Read.Api.Application.CommandHander.UserRoleHander
{
    public class GetUserRoleCommandHander : IRequestHandler<GetUserRoleCommand, ApiResult<List<GetUserRoleDto>>>
    {

        private readonly IMapper mapper;
        private readonly IBaseRequsitory<UserRole> baseRequsitory;

        public GetUserRoleCommandHander(IMapper mapper, IBaseRequsitory<UserRole> baseRequsitory)
        {
            this.mapper = mapper;
            this.baseRequsitory = baseRequsitory;
        }

        public Task<ApiResult<List<GetUserRoleDto>>> Handle(GetUserRoleCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<GetUserRoleDto>> result = new ApiResult<List<GetUserRoleDto>>();

            var entity = baseRequsitory.GetAllAsync();


            result.Code = ApiEnum.显示成功;
            result.Msg = ApiEnum.显示成功.ToString();
            result.Data = mapper.Map<List<GetUserRoleDto>>(entity);

            return Task.FromResult(result);
        }
    }
}
